package cn.isjinhao.se.sql.function.handler.date;

import cn.isjinhao.se.sql.function.handler.ErrorReportableFunctionHandler;
import cn.isjinhao.se.sql.function.handler.FunctionErrorReporterDelegate;
import cn.isjinhao.se.sql.grammar.CurdStatement;
import cn.isjinhao.se.sql.grammar.statement.CurdStatementType;
import cn.isjinhao.se.sql.grammar.statement.Function;
import cn.isjinhao.se.structure.ResultType;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author ISJINHAO
 * @Date 2021/4/11 14:56
 */
public class NowHandler extends ErrorReportableFunctionHandler {

    @Override
    public String functionName() {
        return "now";
    }

    @Override
    public ResultType resultType() {
        return ResultType.DATE;
    }

    @Override
    public void staticCheck(Function function, CurdStatementType type) {
        List<CurdStatement> parameterList = function.getParameterList();
        if (parameterList != null || !parameterList.isEmpty()) {
            error(FunctionErrorReporterDelegate.FUNCTION_parameter_PARSE, function);
            return;
        }
    }

    @Override
    public Object evaluate(Function function, CurdStatementType type, Object... parameters) {
        return LocalDateTime.now();
    }
}
